"use strict";
const app = new (require('koa'))();
const Router = require('koa-router');
const serve = require('koa-static-cache');
const selfLog = new (require('self-log'))('<%= name %>');
const bodyParser = require('koa-bodyparser');
<% if (session) { -%>
const session = require('koa-session');
<% } -%>
<% if (template) { -%>
const path = require('path');
const render = require('koa-art-template');

// 模板引擎
render(app, {
  root: path.join(__dirname, 'views'),
  extname: '.html',
  cache: false,
  minimize: false
});
<% } -%>
<% if (session) { %>
// session
app.keys = ["<%= name %>_<%= time %>"];
app.use(session({
  key: "<%= name %>:sess", // cookie key
  maxAge: 1800000, // session 有效期: 30(min)
  renew: true // 保持持久状态
}, app)); // 配置 session
<% } %>
app.use(selfLog.requestLogger()); // 日志记录
app.use(serve('./public',{gzip:true,prefix:'/<%= name %>/'})); // 静态资源
app.use(bodyParser()); // post 请求参数

// 路由
const appRouter = new Router({ prefix: '/<%= name %>' });
appRouter.use(require('./routes/index').routes());
app.use(appRouter.routes()).use(appRouter.allowedMethods());

module.exports = app;
